package app.netant.book.xs23;

import org.jsoup.select.Elements;

import app.netant.book.base.BaseDetail;
/**
 * 
 * @author JiaJ
 *
 */
public class Xs23Detail extends BaseDetail {

	public Xs23Detail(String netSite) {
		super(netSite);
		this.preHref = "http://www.23xs.org";
	}

	@Override
	public void analyseTitle() {
		Elements parts = this.select("#wrap .main #centerl #content #post #post-single #post-title h1");
		if(parts.size()>0){
			String title = parts.get(0).text();
			System.out.println("【Title】:"+title);
			
			if(title.endsWith("全文免费阅读")){
				title = title.substring(0,title.length()-6);
			}
			
			this.entity.setNovelName(title);
			this.entity.setNovelFullName(title+".txt");
		}
	}

	@Override
	public void analyseTags() {
		Elements parts = this.select("#wrap .main #centerl #content #post #post-single #post-content ul#post-mate li");
		for(int i=0;i<parts.size();i++){
			String tags = parts.get(i).text();
			int idx = tags.indexOf("：");
			if(idx>0){
				String tagName = tags.substring(0,idx).trim();
				String tagValue = tags.substring(idx+1).trim();
				System.out.println("【Tag】:"+tagName+"="+tagValue);
				this.entity.setTag(tagName, tagValue);
			}
		}
	}

	@Override
	public void analyseMemo() {
		Elements parts = this.select("#wrap .main #centerl #content #post #post-single #post-content #articledesc");
		if(parts.size()>0){
			String memo = parts.get(0).text();
			System.out.println("【Memo】:"+memo);
			this.entity.setNovelMemo(memo);
		}
	}

	@Override
	public void analyseHref() {
		Elements parts = this.select("#wrap .main #centerl #content #post #post-single #post-button a");
		for(int i=0;i<parts.size();i++){
			String txt = parts.get(i).text().trim();
			if(txt.indexOf("TXT全文下载")>=0){
				String href = parts.get(i).attr("href");
				if(href.startsWith("/")){
					href = this.preHref + href;
				}
				System.out.println("【Href】:"+href);
				this.entity.setDownPath(href);
				break;
			}
		}
	}
	
	@Override
	public void analyseType() {
		Elements parts = this.select("#wrap .main #centerl #content #pat a[target='_blank']");
		if(parts.size()>1){
			String type = parts.get(1).text();
			System.out.println("【Type】:"+type);
			this.entity.setNovelType(type);
		}
	}
	
	public static void main(String[] args) {
		Xs23Detail detail = new Xs23Detail("http://www.23xs.org/xiaoshuo/41551.html");
		detail.test();
	}



}
